@echo off
cd %~dp0

if not exist "%EPOMDIR%\pgr5.exe" goto EPOM_ERROR

rem ### DELETE_RELEASE
set CHIP_MODEL=
if not exist .\Project\setenv.bat (
pushd .\Project
call config.bat
popd
if not exist .\Project\setenv.bat goto SETENV_ERROR
)
pushd .\Project
call setenv.bat
popd
rem ### DELETE_RELEASE

set make_cmd=cs-make
set make_option=-s -r CT=ON IS_USE_PGRELIEF=y
rem ### DELETE_RELEASE
if not "%MAKE_OPT%"=="" set make_option=%make_option% %MAKE_OPT%
rem ### DELETE_RELEASE

set make_logfile=log.txt
if exist %make_logfile% del /f %make_logfile%
set make_logout=logoutput.exe %make_logfile%

if exist .\PGRelief_out.csv del /f .\PGRelief_out.csv


rem setting multi compile option.
if not "%ENV_MULTI_JOB_OPT%"=="" goto END_OF_ENV_MULTI_JOB_OPT
if "%NUMBER_OF_PROCESSORS%"=="" goto END_OF_ENV_MULTI_JOB_OPT
if "%ENV_MULTI_JOB_NUM%"=="" set /a "ENV_MULTI_JOB_NUM = %NUMBER_OF_PROCESSORS% + %NUMBER_OF_PROCESSORS% / 2"
set ENV_MULTI_JOB_OPT=-j%ENV_MULTI_JOB_NUM%
goto END_OF_ENV_MULTI_JOB_OPT

:END_OF_ENV_MULTI_JOB_OPT
rem if not "%ENV_MULTI_JOB_OPT%"=="" set make_option=%make_option% MULTI_JOB_OPT=%ENV_MULTI_JOB_OPT%



echo.
echo Building (Only updated files) ...

set make_target=target
%make_cmd% %make_option% %make_target% -C Project 2>>&1 | %make_logout%

if exist .\PGRelief_out.csv .\project\PGReliefCheck.exe .\PGRelief_out.csv 2

echo.
echo %0
echo complete !
goto EXIT



rem ### DELETE_RELEASE
:SETENV_ERROR
echo.
echo "setenv.bat" is not created.
echo Please execute "config.bat" to create "setenv.bat".
goto ERROR



:EPOM_ERROR
echo.
echo "pgr5.exe" is not found.
echo Please set "EPOMDIR" environment variable.
goto EXIT


rem ### DELETE_RELEASE
:ERROR
echo.
echo error !
echo press any key to exit.
pause > nul
goto EXIT





:EXIT
